/*
 * Copyright (c)e 2024-2024.Powered by neflibata
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.liuzian.marketserver.controller;

import com.liuzian.marketserver.dto.R;
import com.liuzian.marketserver.entity.Carts;
import com.liuzian.marketserver.service.serviceImpl.CartsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/carts")
public class CartsController {
    @Autowired
    private CartsServiceImpl cartsServiceImpl;

    /**
     * 购物车
     *
     * @param carts 表单数据
     * @return R
     */
    @PostMapping("/addCarts")
    public R<String> addCarts(@RequestBody Carts carts) {
        return cartsServiceImpl.addCarts(carts);
    }

    /**
     * 购物车查询
     *
     * @param cid 购物车cid
     * @return R
     */
    @GetMapping("/queryCarts")
    public R<Carts> queryCarts(Long cid) {
       return cartsServiceImpl.queryCarts(cid);
    }

    /**
     * 购物车所有商品查询
     *
     * @param uid 用户uid
     * @return R
     */
    @GetMapping("/queryAllCarts")
    public R<List<Carts>> queryAllCarts(Long uid) {
        return cartsServiceImpl.queryAllCarts(uid);
    }

    /**
     * 购物车所有商品查询
     *
     * @param count,price,cid 参数
     * @return R
     */
    @GetMapping("/updateCarts")
    public R<String> updateCarts(int count, double price, Long cid) {
        return cartsServiceImpl.updateCarts(count, price, cid);
    }

    @GetMapping("/delete")
    public R<String> deleteCarts(Long cid) {
        return cartsServiceImpl.deleteCarts(cid);
    }
}
